package com.example.common.file;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;

public class FileMergeUtil {
    public static void mergeFiles(File source, File target) {
        try {
            String content1 = Files.readString(source.toPath());
            String content2 = Files.readString(target.toPath());
            
            if (!content1.equals(content2)) {
                String mergedContent = content1 + "\n" + content2;
                Files.writeString(target.toPath(), mergedContent, 
                    StandardOpenOption.TRUNCATE_EXISTING);
            }
        } catch (Exception e) {
            throw new RuntimeException("文件合并失败", e);
        }
    }
}